import * as constants from '../Constants'
import { 
  get, 
  GET_TYPE_PARAM_LIST, 
  GET_COLOR_PARAM_LIST, 
  GET_Season_PARAM_LIST,
  GET_Size_PARAM_LIST,
  GET_Shopgrade_PARAM_LIST,
  GET_SupplierStyle_LIST,
  GET_Fabric_LIST,
  GET_DataPermission_LIST } from '../../service/api'


export interface GetTypeParamList {
  type: constants.GetTypeParamList
  payload: Promise<any>
}

export interface GetTypeParamList_PENDING {
  type: constants.GetTypeParamList_PENDING
  payload: Promise<any>
}

export interface GetTypeParamList_FULFILLED {
  type: constants.GetTypeParamList_FULFILLED
  payload: any
}

export interface GetTypeParamList_PAGE {
  type: constants.GetTypeParamList_PAGE
  payload: any
}

export interface RECORD_TypeParam {
  type: constants.RECORD_TypeParam
  payload: any
}
export type TypeParamAction = GetTypeParamList | 
  GetTypeParamList_FULFILLED | 
  GetTypeParamList_PENDING | 
  GetTypeParamList_PAGE |
  RECORD_TypeParam

export function GetTypeParamList(param: any, type: number): GetTypeParamList {
  let url = ''
  switch (type) {
    case 1:
      url = GET_TYPE_PARAM_LIST
      break
    case 2:
      url = GET_COLOR_PARAM_LIST
      break
    case 3:
      url = GET_Season_PARAM_LIST
      break
    case 4:
      url = GET_Size_PARAM_LIST
      break
    case 5:
      url = GET_Shopgrade_PARAM_LIST
      break
    case 6:
      url = GET_SupplierStyle_LIST
      break
    case 7:
      url = GET_Fabric_LIST
      break
    case 8:
      url = GET_DataPermission_LIST
      break
  }
  return {
    type: constants.GetTypeParamList,
    payload: get(url, param)
  }
}
export function recordTypeParam(param: any): RECORD_TypeParam {
  return {
    type: constants.RECORD_TypeParam,
    payload: param
  }
}
export function clearTypeParam(): RECORD_TypeParam {
  return {
    type: constants.RECORD_TypeParam,
    payload: {}
  }
}
export function page(page: any): GetTypeParamList_PAGE {
  return {
    type: constants.GetTypeParamList_PAGE,
    payload: page
  }
}